package kr.go.nih.biomedi.pSEVA.bean;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Register {
	private String userID;
	private String userPassword;
	private static Register instance = new Register();
	
	public String getUserID() {
		return userID;
	}
	public void setUserID(String userID) {
		this.userID = userID;
	}
	public String getUserPassword() {
		return userPassword;
	}
	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}
	
	private static Register getInstance() {
		if (instance == null) {
			return new Register();
		} else {
			return instance;
		}
	}
	
	private Connection getConnection() throws ClassNotFoundException, SQLException {
		String url = "jdbc:mysql://localhost/pSEVA";
		String user = "root";
		String password = "tlsehddl1";
		
		Class.forName("com.mysql.jdbc.Driver");
		Connection c = DriverManager.getConnection(url, user, password);
		
		return c;
 
	}
	
	public void doRegister() throws ClassNotFoundException, SQLException {
		String id = getUserID();
		String pwd = getUserPassword();

		
		System.out.println(id + pwd);
		
		Connection conn = getConnection();
		
		PreparedStatement ps = conn.prepareStatement("Insert into person(userID, userPassword) values (?,?);");
		ps.setString(1, id);
		ps.setString(2, pwd);
		
		ps.executeUpdate();
		
		ps.close();
		conn.close();
	}
}
